<?php
/**
 * ueditor 在线编辑器
 *
 * 使用举例：
 * {ueditor name="ueditor_content" width="700" height="250"  lang="zh-cn" items="default"}
 */
function smarty_function_ueditor($params)
{
  $params['height'] = empty($params['height']) ? '600': $params['height'];
  $params['name'] = empty($params['name']) ? 'content': $params['name'];
  $params['lang'] = empty($params['lang']) ? 'zh-cn': $params['lang']; //可选择的语言
  $params['items'] = empty($params['items']) ? 'default': $params['items']; 
  if($params['items'] === 'simple') 
  {
    
  }
  else
  {
    $params['width'] = empty($params['width']) ? '800': $params['width'];
    $items = "[   
           'fullscreen', 'source', '|', 'undo', 'redo', '|',   
           'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',   
           'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',   
           'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',   
           'directionalityltr', 'directionalityrtl', 'indent', '|',   
           'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',   
           'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',   
           'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map',  'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',   
           'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',   
           'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',   
           'searchreplace','drafts'   
       ]";
  }
  $editor = '<script charset="utf-8" src="/static/public/ueditor/ueditor.config.js"></script>
  <script charset="utf-8" src="/static/public/ueditor/ueditor.all.js"></script>
  <script charset="utf-8" src="/static/public/ueditor/lang/'.$params["lang"].'/'.$params["lang"].'.js"></script>
  <textarea id="editor_id" name="'.$params["name"].'">'.$params["value"].'
  </textarea>
  <script>
	UE.getEditor("editor_id",{
	  removeFormatTags:"",
	  allowDivTransToP:false,
	  autoFloatEnabled:false,
	  autoHeightEnabled:false,
	  initialFrameHeight:"'.$params["height"].'",
	  initialFrameWidth:"'.$params["width"].'",
	  toolbars: ['.$items.']
	 });
	</script>
  ';
  return $editor;
}